<?php
class Admin extends Base{
	public function index(){
		$this->db();
		$name=NULl;
		if (isset($_GET['name']) && !empty($_GET['name'])){
			$name=$_GET['name'];
		}
		
		if (isset($_GET['id']) && !empty($_GET['id'])){
			$this->mysqli->query("delete from admin where id='".$_GET['id']."' ");
		}
		
		include_once(_template());
	}
	 
	public function edit(){
		if (isset($_GET['id']) && !empty($_GET['id'])){
			 $id=$_GET['id'];
		}else{
			exit;
		}
		$this->db();
		$sql="select * from admin where id='".$id."' limit 0,1 ";
		$query = $this->mysqli->query($sql);
		$userInfo=$query->fetch_array();
		include_once(_template());
	}
	
	public function add(){
		if (isset($_POST['name']) && !empty($_POST['name'])){
			$this->db();
			$name=$_POST['name'];
			$nickname=$_POST['nickname'];
			$pwd=md5($_POST['pwd']);
			$this->mysqli->query("insert into admin(name,nickname,pwd,createtime)
				values('".addslashes($name)."', '".addslashes($nickname)."', '".$pwd."', '".date("Y-m-d H:i:s")."')
				");
			echo json_encode(array('s'=>'yes'));
		    exit;
		}
		include_once(_template());
	}
	
	public function save(){
		if (isset($_GET['id']) && !empty($_GET['id'])){
			$id=$_GET['id'];
		}else{
			exit;
		}
		$this->db();
		if (isset($_POST['pwd']) && !empty($_POST['pwd'])){
			$sql="update admin set name='".$_POST['name']."',nickname='".$_POST['nickname']."',
					pwd='".md5($_POST['pwd'])."'
				 where id='".$id."'   ";
		}else{
			$sql="update admin set name='".$_POST['name']."',nickname='".$_POST['nickname']."'
				 where id='".$id."'   ";
		}

		$query = $this->mysqli->query($sql);
		echo json_encode(array('s'=>'yes'));
		exit;
		
	}
	 

}
?>